<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<link th:replace="fragments/dependency :: edit-css">

<title>优铺Admin</title>
</head>

<body style="background: #fff; margin-top: 7px;">
	<div class="right_col" style="background: #F7F7F7">
		<div class="row">
			<div class="col-md-12 col-sm-12 col-xs-12">
				<div class="x_panel">
					<div class="x_title">
						<h2>首页更新</h2>

						<div class="clearfix"></div>
					</div>
					<div class="x_content">
						<br>
						<form id="demo-form2" class="form-horizontal form-label-left"
							novalidate="">
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">
									编号 ：<span class="required" th:text="${entity.id}"></span>
								</label> <input type="hidden" name="id" th:value="${entity.id}" />
							</div>

							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">
									所属模块: <span class="required" th:text="${entity.module?.name}"></span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input type="hidden" name="moduleId" required="required"
										th:value="${entity.module?.id}">
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">
									关联新闻编号 <span class="required"></span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input type="text" name="articleId"
										th:value="${entity.article?.id}" required="required"
										class="form-control col-md-7 col-xs-12">
								</div>
							</div>
							
							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">
									封面预览 <span class="required"></span>
								</label>
								<div id="upload-file-preview" class="col-md-6 col-sm-6 col-xs-12">
									<img th:src="${@environment.getProperty('static.domain') + entity.coverUrl}" style="width:110px;height:110px;">
								</div>
							</div>
							
							<div class="form-group" th:if="${param.readonly[0]} != 'y'">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">
									展示封面 <span class="required"></span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<div id="upload-picker">选择文件</div>
									<input type="hidden" name="coverUrl" th:value="${entity.coverUrl}">
									
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">
									展示标题 <span class="required"></span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input type="text" name="title" th:value="${entity.title}"
										required="required" class="form-control col-md-7 col-xs-12">
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">
									简单描述 <span class="required"></span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input type="text" name="description"
										th:value="${entity.description}" required="required"
										class="form-control col-md-7 col-xs-12">
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">
									排序 <span class="required"></span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input type="text" name="sort" th:value="${entity.sort}"
										required="required" class="form-control col-md-7 col-xs-12">
								</div>
							</div>

							<div class="ln_solid"></div>
							<div class="form-group">
								<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
									<button class="btn btn-primary" type="reset">重置</button>
									<button type="button" id="save" class="btn btn-success">提交</button>
								</div>
							</div>

						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div th:replace="fragments/dependency :: edit-js"></div>
	<script type="text/javascript">
	$(function() {
		var uploader = upUpload
				.createWithPreview(
						"https://static.ucaiworld.com/ueditor/jsp/controller.jsp?action=uploadimage&watermark=true",
						"upload-picker", "upload", 'upload-file-preview', 110, 110, adminLayer

				);
		uploader.startUpload = function() {
			
		}
		uploader.uploadAccept = function(obj, ret) {
			$("input[name=coverUrl]").val(ret.url).trigger("validate");
		}
	})
		var update = {
			init : function() {
				update.initValidate();
				$("#save").on('click', function() {
					$('form').submit();
				});
			},
			initValidate : function() {
				formValidator.rules = {

				};

				formValidator.fields = {
					articleId : 'required;',

				};
				//表单提交的实体获取函数
				formValidator.getEntity = function() {
					return {
						coverUrl : $("input[name=coverUrl]").val(),
						title : $("input[name=title]").val(),
						module : $("input[name=moduleId]").val(),
						article : $("input[name=articleId]").val(),
						description : $("input[name=description]").val(),
						sort : $("input[name=sort]").val(),
						status : 100,
					};
				}
				//初始化验证路径以及回调函数
				formValidator.init('/moduleArticle/homeUpdate/?id='
						+ $('input[name=id]').val(), function(data) {
					if (data.id > 0) {
						adminLayer.alert({
							content : '更新成功',
							yes : function() {
								window.parent.location.reload();
							},
							end : function() {

							}
						});
					}
				});
			}
		}
		update.init();
	</script>

	<script th:replace="fragments/detailForm :: detailForm"></script>
</body>
</html>
